import { ManageCommonAPI } from '@/pages/type';
import { getLevelFirstJson, getLevelZeroJson } from '@/utils';

const getSearchList = (queryTypeObj: Record<string, any>, tabSwitchType: string): ManageCommonAPI.ISearchList => {
  const switchTabObj = queryTypeObj?.find((item) => item?.key === tabSwitchType);
  let orgDeptList: any[] = [];
  if (switchTabObj?.params?.params == 'ownCompanyID') {
    orgDeptList = getLevelZeroJson();
  } else if (switchTabObj?.params?.params == 'ownDepartmentID') {
    orgDeptList = getLevelFirstJson();
  }
  // 名称 资金来源 状态 资金流向 支付方式 相对方
  let searchConfig: ManageCommonAPI.ISearchList = [
    {
      name: 'subject',
      placeholder: '标题',
      label: '标题',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'defName',
      placeholder: '类型',
      label: '类型',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'nodeName',
      placeholder: '当前环节',
      label: '当前环节',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'createDateTime',
      placeholder: '',
      label: '时间',
      componentType: 'RangePicker',
      allowClear: true,
      md: tabSwitchType == 'NeedToDoTasks' ? 8 : 6,
      sm: 24,
      whetherSenior: false,
      showTabsKey: 'notTask',
    },
    {
      name: 'endTime',
      placeholder: '办理',
      label: '办理时间',
      componentType: 'RangePicker',
      allowClear: true,
      md: tabSwitchType == 'NeedToDoTasks' ? 8 : 6,
      sm: 24,
      whetherSenior: false,
      showTabsKey: 'handTask',
    },
    // {
    //   name: 'assigneeFormName',
    //   placeholder: '办理',
    //   label: '办理',
    //   componentType: 'DeptAndUser',
    //   dataSource: orgDeptList,
    //   allowClear: true,
    //   md: 5,
    //   sm: 24,
    //   whetherSenior: false,
    //   formOrgType: {
    //     COMP: 'assigneeCompanyID',
    //     DEPT: 'assigneeDepartmentID',
    //     POS: 'assigneePositionID',
    //     USER: 'assigneeID',
    //   }, //获取组织机构表单name, componentType: 'DeptAndUser', 必传
    //   showTabsKey: 'handTask',
    // },

    {
      name: queryTypeObj?.params,
      placeholder: '权限参数',
      label: '权限参数',
      componentType: 'QueryParams',
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: true,
    },
  ];

  searchConfig = searchConfig?.filter((item: any) => (tabSwitchType == 'NeedToDoTasks' ? item?.showTabsKey != 'handTask' : item?.showTabsKey != 'notTask'));
  return searchConfig;
};

const taskSearchParams = () => {
  // 自定义各自业务中审批任务搜索字段
  const taskCheckConfig = [
    {
      fieldName: 'contractName',
      fieldType: 'String',
      fieldParam: 0,
      fieldUse: 0,
      searchType: 0,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'contractCode',
      fieldType: 'String',
      fieldParam: 0,
      fieldUse: 0,
      searchType: 0,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'projectName',
      fieldType: 'String',
      fieldParam: 0,
      fieldUse: 0,
      searchType: 0,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'capitalDir',
      fieldType: 'Integer',
      fieldParam: 1,
      fieldUse: 0,
      searchType: 1,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'payStyle',
      fieldType: 'String',
      fieldParam: 1,
      fieldUse: 0,
      searchType: 1,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'majorFlag',
      fieldType: 'Integer',
      fieldParam: 1,
      fieldUse: 0,
      searchType: 1,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'sumInTax',
      fieldType: 'BigDecimal',
      fieldParam: 0,
      fieldUse: 0,
      searchType: 1,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'budgetFlag',
      fieldType: 'Integer',
      fieldParam: 1,
      fieldUse: 0,
      searchType: 1,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'createTime',
      fieldType: 'Date',
      fieldParam: 0,
      fieldUse: 0,
      searchType: 0,
      isSearch: 0,
      seq: 0,
    },

    {
      fieldName: 'cancelTime',
      fieldType: 'Date',
      fieldParam: 0,
      fieldUse: 0,
      searchType: 0,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'cancelReason',
      fieldType: 'String',
      fieldParam: 0,
      fieldUse: 0,
      searchType: 0,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'contractInfo',
      fieldType: 'String',
      fieldParam: 0,
      fieldUse: 0,
      searchType: 0,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'pID',
      fieldType: 'String',
      fieldParam: 0,
      fieldUse: 0,
      searchType: 0,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'changeWay',
      fieldType: 'Integer',
      fieldParam: 1,
      fieldUse: 0,
      searchType: 1,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'id',
      fieldType: 'String',
      fieldParam: 0,
      fieldUse: 0,
      searchType: 0,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'ownCompanyID',
      fieldType: 'String',
      fieldParam: 5,
      fieldUse: 0,
      searchType: 1,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'ownDepartmentID',
      fieldType: 'String',
      fieldParam: 4,
      fieldUse: 0,
      searchType: 1,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'ownPositionID',
      fieldType: 'String',
      fieldParam: 3,
      fieldUse: 0,
      searchType: 1,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'ownerID',
      fieldType: 'String',
      fieldParam: 2,
      fieldUse: 0,
      searchType: 0,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'createCompanyID',
      fieldType: 'String',
      fieldParam: 5,
      fieldUse: 0,
      searchType: 1,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'createDepartmentID',
      fieldType: 'String',
      fieldParam: 4,
      fieldUse: 0,
      searchType: 1,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'createPositionID',
      fieldType: 'String',
      fieldParam: 3,
      fieldUse: 0,
      searchType: 1,
      isSearch: 0,
      seq: 0,
    },
    {
      fieldName: 'createrID',
      fieldType: 'String',
      fieldParam: 2,
      fieldUse: 0,
      searchType: 0,
      isSearch: 0,
      seq: 0,
    },
  ];
  return taskCheckConfig;
};

export { getSearchList, taskSearchParams };
